package String.s7;

public class test_238 {
    public static void main(String[] args) {
        int[] nums={1,2,3,4};
        int[] rs=new Solution().productExceptSelf(nums);
        for(int i=0;i<rs.length;i++){
            System.out.println(rs[i]);
        }
    }
}
class Solution {
    public int[] productExceptSelf(int[] nums) {
        int len=nums.length;
        int[] l=new int[len];
        int[] r=new int[len];

        l[0]=1;
        for(int i=1;i<len;i++){
            l[i]=nums[i-1]*l[i-1];
        }
        r[len-1]=1;
        for(int i=len-2;i>=0;i--){
            r[i]=nums[i+1]*r[i+1];
        }

        int[] rs=new int[len];
        for(int i=0;i<len;i++){
            rs[i]=l[i]*r[i];
        }
        return rs;
    }
}
